Generating docs programmatically
You can use the Generatorclass Generatorts-docs/generator/Generator class to generate documentation automatically. That class doesn't extract any information from any projects, so you'll have to do that yourself using the TypescriptExtractorclass TypescriptExtractorextractor/extractor/TypescriptExtractor class.
Extracting information
You can check out all the options the extractor accepts hereinterface TypescriptExtractorSettingsextractor/extractor/TypescriptExtractorSettings.
import { TypescriptExtractorclass TypescriptExtractorextractor/extractor/TypescriptExtractor } from "@ts-docs/extractor";
const entryPoints = ["./src/index.ts"];
const extractor = new TypescriptExtractorclass TypescriptExtractorextractor/extractor/TypescriptExtractor({
entryPoints,
maxConstantTextLength: 1024,
// Recommended
ignoreFolderNames: ["lib"]
});
Generating documentation
You can check out all the options the extractor accepts hereinterface TsDocsOptionsts-docs/TsDocsOptions.
import { Generatorclass Generatorts-docs/generator/Generator } from "@ts-docs/ts-docs";
const generator = new Generatorclass Generatorts-docs/generator/Generator({
entryPoints,
name: "My Project",
out: "./docs",
structure: "default-docs-structure"
});
generator.generate(extractor);
Customizing output
Let's say you don't want to save the generated files to your computer, but instead send them to a hosting platform for example. You can pass a custom FileHostinterface FileHostts-docs/fileHost/FileHost to the Generatorclass Generatorts-docs/generator/Generator constructor:
import { FileHostinterface FileHostts-docs/fileHost/FileHost, Generatorclass Generatorts-docs/generator/Generator } from "@ts-docs/ts-docs";
import path from "path";
// We'll keep the files and their contents here.
const files = new Map();
const MyFileHost: FileHostinterface FileHostts-docs/fileHost/FileHost = {
exists: (path) => files.has(path),
createFile: (basePath, folder, file, content) => {
const folderPath = path.join(basePath, folder);
files.set(path.join(folderPath, file), content);
return folderPath;
},
copyFolder: (origin, destination) => {
// ...
},
readFile: (path) => {
if (!files.has(path)) throw new Erorr("...");
return files.get(path);
},
createDir: (p, name) => path.join(p, name),
writeFile: (path, content) => files.set(path, content),
getDocumentStructure: () => false
}
const gen = new Generatorclass Generatorts-docs/generator/Generator({
//...
}, MyFileHost);